package com.htd.base.common.config.local;

import com.htd.base.common.constant.BaseConstant;

import java.util.Map;

public class TranslateThreadLocal {

    private static final ThreadLocal<Map<String, String>> threadLocal = new ThreadLocal<Map<String, String>>();
    private TranslateThreadLocal() {
    }
    /**
     * 对当前线程中的map域设置属性值，不会对其他线程产生影响  Thread.currentThread()
     * @param map
     */
    public static void set(Map<String, String> map){
        threadLocal.set(map);
    }

    public static Map<String, String> get(){
        return threadLocal.get();
    }

    public static boolean getSwitch(){
        return BaseConstant.ThreadLocal.TRAN_SWITCH_OPEN.equals(threadLocal.get().get(BaseConstant.ThreadLocal.TRAN_SWITCH));
    }

    public static String getLangCode(){
        return threadLocal.get() == null ? null : threadLocal.get().get(BaseConstant.ThreadLocal.TRAN_LANG_CODE);
    }

    /**
     * 本质上是调用当前线程的remove，不会对其他线程产生影响
     */
    public static void remove(){
        threadLocal.remove();
    }
}
